//*****************************************************************
// Project2.cpp
//
//  Created on: Jan 21, 2012
//      Author: Christopher Wood
//              Robert Livosi
//
//  $Id: Project2.cpp 30 2012-01-29 21:29:24Z caw4567 $
//*****************************************************************

// Module includes
#include "Project2.h"
#include "IOThreadGroup.h"
#include "Controller.h"
#include "OperatorThread.h"

/**
 * The main entry point for the controller program.
 */
int main(int argc, char *argv[])
{
	// Get permission to the hardware
	int privity_err = ThreadCtl(_NTO_TCTL_IO, NULL);
	if (privity_err == -1)
	{
		cerr << "Can't get root permissions" << endl;
		exit(-1);
	}

	// Create and then start all threads
	Controller* controller = new Controller(TRANSFORM_ALGORITHM_PID);
	IOThreadGroup* ioGroup = new IOThreadGroup(controller);
	controller->setIOGroup(ioGroup);
	OperatorThread* theOperator = new OperatorThread(controller, ioGroup);
	ioGroup->runInputThread();
	ioGroup->runOutputThread();
	controller->run();
	theOperator->run();

	// Wait until the control thread is complete.
	while (!theOperator->isComplete())
	{
	}

	return EXIT_SUCCESS;
}
